package com.young.shop_admin.services.impl;

import com.young.shop_admin.dao.OrderDao;
import com.young.shop_admin.dao.impl.OrderDaoImpl;
import com.young.shop_admin.pojo.entity.Goods;
import com.young.shop_admin.pojo.entity.Order;
import com.young.shop_admin.pojo.entity.Page;
import com.young.shop_admin.pojo.vo.OrderGoodsDetailVO;
import com.young.shop_admin.services.OrderServices;

import java.sql.SQLException;
import java.util.List;

public class OrderServicesImpl implements OrderServices {
    private OrderDao orderList = new OrderDaoImpl();

    @Override
    public List<Order> getAllOrders() {
        return orderList.getAllOrders();

    }

    @Override
    public Order checkSendOrder(Integer id) {
        //判断id是否为空
        if (id == null) {
            throw new RuntimeException("系统错误");
        }

        //根据用户id修改用户信息
        int i = orderList.updateOrderById(id, "已发货");
        if (i != 1) {
            throw new RuntimeException("系统错误");
        }
        //根据用户id查询用户信息
        return orderList.queryOrderById(id);
    }

    @Override
    public Order checkCancelOrder(Integer id) {
        //判断id是否为空
        if (id == null) {
            throw new RuntimeException("系统错误");
        }
        //根据用户id修改用户信息
        int i = orderList.updateOrderByIdForCancel(id, "已取消");
        if (i != 1) {
            throw new RuntimeException("系统错误");
        }
        //根据用户id查询用户信息
        return orderList.queryOrderById(id);
    }

    @Override
    public List<OrderGoodsDetailVO> checkOrderDetail(Integer id) {
        //判断id是否为空
        if (id == null) {
            throw new RuntimeException("系统错误");
        }
        //根据id查询商品详细
        return orderList.queryOrderGoodsDetailById(id);
    }

    @Override
    public List<Order> selectOrderListByDate(String beforeDate, String afterDate) {
        //判断Date是否为空,为空赋值
        if (beforeDate == null || "".equals(beforeDate.trim())) {
            beforeDate = "1970-01-01";
        }
        if (afterDate == null ||"".equals(afterDate.trim())) {
            afterDate = "2999-01-01";
        }
        System.out.println("beforeData"+beforeDate);
        System.out.println("after"+afterDate);
        //根据时间查询订单列表
        return orderList.getOrderByDate(beforeDate, afterDate);

    }

}
